package com.gpzx.zx.module.home.frame.view

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import com.gpzx.zx.module.home.frame.model.QKLAuthorInfo
import com.gpzx.zx.module.home.frame.model.QKLNewsInfo
import com.gpzx.zx.module.home.ui.activity.AuthorActivity
import com.gpzx.zx.module.home.ui.activity.InfoWebViewActivity
import com.gpzx.zx.module.home.ui.adapter.AuthorListAdapter
import com.gpzx.zx.module.home.ui.fragment.AuthorListFragment
import com.wkq.base.frame.mosby.delegate.MvpView
import java.util.*

/**
 * 作者: 吴奎庆
 *
 * 时间: 2020/7/15
 *
 * 简介:
 */
class AuthorListView : MvpView {
    var mAdapter: AuthorListAdapter? = null

    fun initView() {
        initToolBar("名家")

        mFragment.binding.rvContent.layoutManager = LinearLayoutManager(mFragment.activity)
        mAdapter = AuthorListAdapter(mFragment.activity as Context)
        mFragment.binding.rvContent.adapter = mAdapter

        mAdapter?.setOnViewClickListener(object : AuthorListAdapter.OnAdapterViewClickListener<QKLAuthorInfo> {
            override fun onViewClick(v: Int, program: QKLAuthorInfo?) {
                if (v == 1) {
                    AuthorActivity.newInstance(mFragment.activity as Context,program!!.authorId+"")
                } else {
                    InfoWebViewActivity().newInstance(mFragment.activity as Context, "qkl_author_news", program?.newsInfo!!.id, program?.newsInfo!!.news_title)
                }
            }


        })
    }

    private fun initToolBar(title: String?) {
        mFragment.binding.tvTitle.setText(title)
    }

    fun showData(list: List<QKLNewsInfo>) {
        var newData = ArrayList<QKLAuthorInfo>()
        var authorName :String = ""
        list.forEach {
            var info = QKLAuthorInfo();
            if (it.news_author_name.equals(authorName)) {
                info.newsInfo = it
                info.type=2
            } else {
                info.authorName = it.news_author_name
                info.authorId = it.news_author_id
                info.authorFans = it.news_author_funs
                info.authorLikes = it.news_author_support
                info.authorIcon = it.news_author_icon
                info.authorNews = it.news_author_news
                info.type=1
                authorName= it.news_author_name.toString()

            }
            newData.add(info)
        }
        mAdapter!!.addItems(newData)
    }

    var mFragment: AuthorListFragment

    constructor(fragment: AuthorListFragment) {
        mFragment = fragment;
    }

}